<template>
	<view class="colle page bgf6" >

		


		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>主板编号</text>
			<view class="flex flexC">

				<view>
					<input class="c8e px8" :value="device.device_sn"></input>
				</view>
				<image @click="clickScan" class="scan"  src="../static/scan.png"></image>
			</view>
		</view>
		
		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>在线状态</text>
			<view class="flex flexC">
		
				<view>
					<text v-if="device.status == 'online'" class="c8e px8">在线</text>
					<text v-else class="c8e px8">离线</text>
					
				</view>
				<text class="arrowR dinline mt2"></text>
			</view>
		</view>
		
		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>SN编号</text>
			<view class="flex flexC">
		
				<view>
					<text class="c8e px8">{{device.sn}}</text>
				</view>
				<text class="arrowR dinline mt2"></text>
			</view>
		</view>
		
		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>SIM卡号</text>
			<view class="flex flexC">
		
				<view>
					<text class="c8e px8">{{device.sim}}</text>
				</view>
				<text class="arrowR dinline mt2"></text>
			</view>
		</view>
		
		
		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>信号强度</text>
			<view class="flex flexC">
		
				<view>
					<text class="c8e px8">{{device.signal_num}}</text>
				</view>
				<text class="arrowR dinline mt2"></text>
			</view>
		</view>
		

		<button @click="getInfo" hover-class="none" class="r40 bg41 m10 fs16 py16">读取信息</button>
	
		<button @click="openRoomCmd(60)"  hover-class="none" class="r40 bg41 m10 fs16 py16">开1分钟</button>
		<button @click="openRoomCmd(600)" hover-class="none" class="r40 bg41 m10 fs16 py16">开10分钟</button>
		<button @click="openRoomCmd(1800)" hover-class="none" class="r40 bg41 m10 fs16 py16">开30分钟</button>
		<button @click="openRoomCmd(0)" hover-class="none" class="r40 bg41 m10 fs16 py16">关闭</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

				device_sn:'',
				device:null
			};
		},
		onLoad() {
		
		
		},
		onShow() {
		},
		methods: {
			
			
			openRoomCmd(time) {
			
				let param = {
					device_sn:this.device.device_sn,
					sn:this.device.sn,
					sec: time
				};
				let that = this;
				this.$api.testOpen(param).then(res => {
			
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 1) {
						
					} else {
			
					}
				})
			},
			
			clickScan(){
				let that = this;
				uni.scanCode({
				    onlyFromCamera: false, // 是否只从相机扫码，不从相册选择图片
				    scanType: ['qrCode', 'barCode'], // 扫描的类型
				    success: function (res) {
						that.device_sn = res.result;
				        console.log('扫描结果：', res.result);
				        console.log('扫描条码类型：', res.scanType);
				        console.log('字符集：', res.charSet);
				        console.log('路径：', res.path); // 当所扫的码为小程序码时会返回此项
						that.getInfo();
				    },
				    fail: function (err) {
				        console.error('扫码失败：', err);
				    },
				    complete: function () {
				        console.log('扫码操作完成');
				    }
				});
			
			},	


			getInfo() {
				let param = {
					device_sn: this.device_sn
				}
				let that = this;
				this.$api.testInfo(param).then(res => {
					console.info(res);
					if (res.code == 1) {
						that.device = res.data;
					} else {

					}
				})

			}

		}
	}
</script>

<style lang="scss" scoped>
	.colle {
		
		.scan{width: 100rpx;height: 100rpx;}
		.head{
			width: 90rpx;
			height: 90rpx;
		}
		.w20 {
			width: 80rpx;
			height: 80rpx;
		}

		.w28 {
			width: 56rpx;
		}

		.maxH {
			height: 60vh;
		}
	}
</style>
